package com.googlecode.uipipedream.impl;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.Observable;
import java.util.Observer;

import com.googlecode.uipipedream.spec.ColourModel;

public class ColourPanel extends Canvas implements Observer {
	private static final long serialVersionUID = 5525409707001024080L;
	private ColourModel model;
	
	@Override public Dimension preferredSize() { return new Dimension(20, 20); }
	@Override public Dimension minimumSize() { return new Dimension(5, 5); }
	@Override public void update(Observable o, Object arg) { repaint(0); }
	
	public ColourPanel(ColourModel model) {
		this.model = model;
		model.addObserver(this);
		setBackground(Color.black);
	}
	
	@Override public void paint(Graphics g) {
		g.setColor(model.getColor());
		g.fillRect(3, 3, getWidth() - 4, getHeight() - 4);
		g.setColor(Color.white);
		g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
	}

}